package com.japanesee_learning.activity;

import com.japanesee_learning.until.ConstantsUntil;
import com.japanesee_learning.until.ImagesUntil;
import com.japanesee_learning.until.MessageUntil;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

public class AboutActivity extends Activity {
	private String TAG = AboutActivity.class.getSimpleName();
	private ImageView mImageIco;
	private TextView mTxtHeader;
	private ImageView mImageAvar;
	private ImagesUntil mObjImage;
	private Context mContext;
	private MessageUntil mObjMessage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		try {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_about);
			getWindow().setSoftInputMode(
					WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
			mContext = this;
			mObjImage = new ImagesUntil(mContext);
			mObjMessage = new MessageUntil(mContext);

			mImageIco = (ImageView) findViewById(R.id.menuViewButton);
			mTxtHeader = (TextView) findViewById(R.id.txtHeaderTitle);
			mImageAvar = (ImageView) findViewById(R.id.menuUserAvatar);
			mTxtHeader.setText(R.string.about);
			mImageIco.setImageResource(R.drawable.ico_hira);

			/**
			 * ================================================================
			 * ==== == Setting image avatar
			 * **/
			Resources resources = this.getResources();
			Uri selectedImage = Uri
					.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
							+ "://"
							+ resources
									.getResourcePackageName(R.drawable.user_avatar)
							+ '/'
							+ resources
									.getResourceTypeName(R.drawable.user_avatar)
							+ '/'
							+ resources
									.getResourceEntryName(R.drawable.user_avatar));

			Bitmap bitmap = mObjImage.getBitmap(selectedImage);
			bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(),
					bitmap.getHeight(), true);

			// Setting rotate following rotation of image
			Matrix matrix = new Matrix();
			matrix.postRotate(0);
			Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
					bitmap.getWidth(), bitmap.getHeight(), matrix, true);

			// Set round corner
			Bitmap roundedBitmap = mObjImage.setRoundCorner(rotatedBitmap, 35);

			// Set image into imageview
			// imageView.setBackgroundResource(R.drawable.border_imageview);
			mImageAvar.setImageBitmap(roundedBitmap);
		} catch (Exception ex) {
			Log.v(TAG, "onCreate :: " + ex.toString());
			mObjMessage.showMessageError(ConstantsUntil.MESSAGE_ERROR);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}
